package cn.kgc.cjk_yy.controller;


import cn.kgc.cjk_yy.pojo.AppInfo;
import cn.kgc.cjk_yy.pojo.BackendUser;
import cn.kgc.cjk_yy.pojo.DataDictionary;
import cn.kgc.cjk_yy.service.BackendUserService;
import cn.kgc.cjk_yy.service.impl.BackendUserServiceImpl;
import cn.kgc.cjk_yy.tools.PageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/*系统管理员的控制*/
@Controller
public class BackendUserController {

    @Resource
    private BackendUserService backendUserService;
    /**
     * 系统管理员的登录
     * @return 
     */
    //后台管理员登录
    @RequestMapping(value="backend_user_login",method = RequestMethod.POST)
    public String backend_user_login(@RequestParam("usercode") String usercode, @RequestParam("password") String password, HttpServletRequest request) throws Exception {

        BackendUser user= backendUserService.backend_user_login(usercode, password);
        if(null==user){
            return "backend_user_login";
        }else{
            request.getSession().setAttribute("backendUser",user);
            return "backend_user/main";
        }
    }

  /*  系统的注销*/
    public String out(HttpSession session){
        session.removeAttribute("backendUser");
        session.invalidate();
        return "start";
    }

    /*用户模糊查询用户列表信息*/
    @RequestMapping("/showUser")
    public String showUser(String pagenum, AppInfo appInfo, Model model) {
        PageDto pageDto=backendUserService.selectPage(pagenum,appInfo);
        pageDto.setUrlpath("showUser");
        model.addAttribute("page",pageDto);
        return "backend_user/applist";
    }

}
